<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
class wms_ctl_admin_stocknotice extends desktop_controller{
    
    var $workground = 'wms_ctl_admin_stocknotice';
    var $pagelimit = 10;
    var $stocknotice_model ;
    public function __construct($app)
    {
        parent::__construct($app);
        $this->member_model = $this->app->model('stocknotice');
        header("cache-control: no-store, no-cache, must-revalidate");
    }
    //备货通知单首页
   function index()
   {
   	
        $actions_base['title'] = app::get('wms')->_('备货通知单');
        $actions_base['actions'] = $custom_actions;
        $actions_base['allow_detail_popup'] = true;
        $actions_base['use_buildin_set_tag'] = false;
        $actions_base['use_buildin_export'] = true;
        $actions_base['use_buildin_filter'] = false;
        $actions_base['use_buildin_recycle'] = false;//是否删除
        $actions_base['use_view_tab'] = false;

        $this->finder('wms_mdl_stocknotice',$actions_base);
    }
    //AX发货单
    function AXIndex(){
    
        $custom_actions[] = array('label'=>app::get('wms')->_('发货'),'submit'=>'index.php?app=wms&ctl=admin_stocknotice&act=syncapi');

        $actions_base['title'] = app::get('wms')->_('AX发货单');
        $actions_base['actions'] = $custom_actions;
        $actions_base['allow_detail_popup'] = true;
        $actions_base['use_buildin_set_tag'] = false;
        $actions_base['use_buildin_export'] = true;
        $actions_base['use_buildin_filter'] = false;
        $actions_base['use_buildin_recycle'] = false;//是否删除

        $actions_base['use_view_tab'] = false;

        $this->finder('wms_mdl_stocknotice',$actions_base);
    }

    //add by ldward 20160817 点击【发货】，调用AX发货接口
    function syncapi()
    {
        $sku = kernel::single('base_component_request');
        $order_info = $sku ->get_post();
        //echo var_dump($order_info);

        $this->AXIndex();
    }

    function add(){
        $stocknotice_model = $this->app->model('stocknotice');

        $arr_order['pam_account']['code'] = $_POST['pam_account']['code'];
        $arr_order['pam_account']['name'] = $_POST['pam_account']['name'];
        $arr_order['pam_account']['param'] = $_POST['pam_account']['param'];
        $arr_order['pam_account']['remark'] = $_POST['pam_account']['remark'];
        if($_POST)
        {
            if($_POST['pam_account']['id'] != '')
            {
                // 修改
                $this->begin();

                $db = kernel::database();
                $db->beginTransaction();

                        ;
                if( $stocknotice_model->update($arr_order['pam_account'], array('id' => $_POST['pam_account']['id'])) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('wms')->_('添加成功！'));
            } 
            else 
            {
                // 添加
                $this->begin();
                $db = kernel::database();
                $db->beginTransaction();
                if( $stocknotice_model->save($arr_order['pam_account']) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('wms')->_('添加成功！'));
            }
        }
    }
    function lmedit(){
        $stocknotice = '';
        if(isset($_GET['id'])){
            $id = $_GET['id'];
            $stocknotice_obj = kernel::single('wms_mdl_stocknotice');
            $stocknotice = $stocknotice_obj->getList('*', array('id'=>$id), 0, 1);

        }
        $this->pagedata['pam_account'] = $stocknotice[0];
        $this->page('admin/stocknotice/new.html');

    }

}
